import os
import cv2
import time
from logger import get_logger

logger = get_logger('Saver')

class ImageSaver:
    def __init__(self, directory='images'):
        self.directory = directory
        os.makedirs(self.directory, exist_ok=True)

    def save(self, frame):
        timestamp = int(time.time())
        filename = os.path.join(self.directory, f"captured_{timestamp}.jpg")
        try:
            cv2.imwrite(filename, frame)
            logger.info(f"Image saved: {filename}")
            return filename
        except Exception as e:
            logger.error(f"Failed to save image: {e}")
            return None